package com.shishuo.cms;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ProsUtils {
	public static void main(String[] args) throws Exception {
		Properties  props = new ProsUtils().loadProps("/shishuocms.properties");
		System.out.println("获取属性值：cms.admin.email="+ props.getProperty("cms.admin.email"));
	}

	public  synchronized Properties loadProps(String properties) throws Exception{
		Properties  props = null ;
		InputStream in = this.getClass().getResourceAsStream(properties);
		if(in == null)
			throw new Exception("Can not find " + properties);
		else{
			props = new Properties();
			props.load(in);
		}
		return props ;
	}
	
	public synchronized boolean saveProps(Properties props,String propertiesFile) throws IOException {
		if(props == null)
			return false;
		String url = this.getClass().getResource(propertiesFile).getFile();
		props.store(new FileOutputStream(url), propertiesFile);
		return true;
	}
}
